package com.iwhalecloud.citybrain.flow.platform.manager.domain.model;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowNextNodeCandidateRepository;
import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @Description 流程节点候选人领域对象
 * @author liujinjian
 * @date 2021-10-22
 * @version 1.0
 */
@Data
@Service
public class FlowNodeCandidateDomain implements Serializable, ApplicationContextAware {

    private static final long serialVersionUID = -1882496370098298888L;

    @Autowired
    private static FlowNextNodeCandidateRepository flowNextNodeCandidateRepository;

    /**
     * 主键key
     */
    private Long id;

    /**
     * 流程实例编号
     */
    @NotNull(message = "流程实例编号不能为空")
    private String processInstanceId;

    /**
     * 节点编码
     */
    @NotNull(message = "节点编码不能为空")
    private String nodeCode;

    /**
     * 数据类型
     */
    private String dataType;

    /**
     * 编码
     */
    @NotNull(message = "编码不能为空")
    private String code;

    /**
     * 名称
     */
    @NotNull(message = "名称不能为空")
    private String name;

    /**
     * 来源节点编码
     */
    private String fromNodeCode;

    public void save() {
        flowNextNodeCandidateRepository.create(this);
    }

    public void update() {
        flowNextNodeCandidateRepository.update(this);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        flowNextNodeCandidateRepository = applicationContext.getBean(FlowNextNodeCandidateRepository.class);
    }
}